<script type="text/javascript">
	var isValid = true;
	function checkSlideShow(index) {		
		var imageUrID = "#file-target-" + index;
		var slideShowTitleID = "#slideShowTitle-" + index;

		var imageUrlVal = jQuery(imageUrID).val();
		var titleVal = jQuery(slideShowTitleID).val();

		if (imageUrlVal == "" || titleVal == "") {
			isValid = false;			
		}
	}

	function validate() {
		isValid = true;
		for (i = 1; i <= 5; i++) {
			checkSlideShow(i);
		}
	}

	jQuery(function() {
		 jQuery('input[name="saveSlideShow"]').click(function() {
			var cmd = jQuery('input[name=cmd]').val();
			if(cmd == 'add'){
			  validate();	
			}							
			if (isValid) {
				submitForm('frmSlideShow');
			} else {
				var cmd = jQuery('input[name=cmd]').val();
				var msg = '';
				if (cmd == 'add') {
					msg = '<span class="v-error-message"><ul><li><spring:message code="warning.add.slide.show.missing.required.field" /></li></ul></span>';
				} else if (cmd = 'edit') {
					msg = '<span class="v-error-message"><ul><li><spring:message code="warning.edit.slide.show.missing.required.field" /></li></ul></span>';
				}
				jQuery('#v-global-message').html(msg);
			}
         });

		jQuery(".image-preview").css("margin-top", "0px");

		jQuery(".file-target").change(function() {
			if (this.files) {
				jQuery(this).parent().parent().parent().parent().find(
						".image-preview").attr("src",
						this.files[0].getAsDataURL());
			} else {
				jQuery(this).parent().parent().parent().parent().find(
						".image-preview").attr("src",
						jQuery(this).val());
			}
       });
	});
</script>